package DAO;

import bean.SubcategoryTelevision;

import java.util.List;

public class SubcategoryTelevisionDao extends BaseDao {
    public int addRelation(int subCategoryId, int televisionId) {
        String sql = "INSERT INTO subcategory_television (sub_category_id, television_id) VALUES (?, ?)";
        return update(sql, subCategoryId, televisionId);
    }

    public int deleteRelationBySubCategoryId(int subCategoryId) {
        String sql = "DELETE FROM subcategory_television WHERE sub_category_id = ?";
        return update(sql, subCategoryId);
    }

    public int deleteRelationByTelevisionId(int televisionId) {
        String sql = "DELETE FROM subcategory_television WHERE television_id = ?";
        return update(sql, televisionId);
    }

    public List<SubcategoryTelevision> getRelationsBySubCategoryId(int subCategoryId) {
        String sql = "SELECT sub_category_id, television_id FROM subcategory_television WHERE sub_category_id = ?";
        return queryForList(sql, SubcategoryTelevision.class, subCategoryId);
    }

    public List<SubcategoryTelevision> getRelationsByTelevisionId(int televisionId) {
        String sql = "SELECT sub_category_id, television_id FROM subcategory_television WHERE television_id = ?";
        return queryForList(sql, SubcategoryTelevision.class, televisionId);
    }
} 